# -*- coding:utf-8 -*-

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from AutoTestBDC.WorkFlow.User import User
from AutoTestBDC.extScript.GetList import GetListValue
from AutoTestBDC.extScript.SeaValue import SeaValue
from time import sleep

class GT(User):
    def __init__(self,driver,username,userpwd,type=None,caseno=None,qlrtype=None):
        super().Login(driver, username, userpwd)
        self.driver = driver
        self.type = type
        self.caseno = caseno
        self.qlrtype = qlrtype

        driver.find_element_by_css_selector(u"img[title=\"申请查询\"]").click()
        SeaValue(driver,caseno,qlrtype)

        glv = GetListValue()
        if qlrtype == "自然人":
            tablexpath = "/html/body/content/div/form/div/div[19]"

        if qlrtype == "法人机构":
            tablexpath = "/html/body/content/div/form/div/div[20]"

        if qlrtype == "其他组织":
            tablexpath = "/html/body/content/div/form/div/div[21]"
        glv.clickvalue(driver, tablexpath ,caseno)

        self.test_tester()

    def test_tester(self,type=None):

        if self.type == "修改重提交":
            self.set_recommit()

        if self.type == "通知客户取件":
            self.set_messageuser()

        super().Logout()

    def set_recommit(self):
        self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_id("modifyEdit"))
        sleep(1)

        self.driver.find_element_by_id("modifyEdit").click()

        self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_id("textarea2B"))
        sleep(2)
        self.driver.find_element_by_id("textarea2B").clear()
        self.driver.find_element_by_id("textarea2B").send_keys(u"修改一下！！")

        self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_id("submitbut1"))
        self.driver.find_element_by_id("submitbut1").click()
        sleep(1)
        self.driver.find_element_by_id("uid").click()
        self.driver.find_element_by_id("submitBtn").click()
        self.driver.find_element_by_css_selector("#commitStep2B > button[type=\"submit\"]").click()

    def set_messageuser(self):
        self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_id("detail-commitB"))
        self.driver.find_element_by_css_selector(
            "html body content div.mainbox1 form div.check-detail-page div.nowrap div button.state_finished").click()
        # self.driver.find_element_by_id("state_finished").click()




